"""
通过链接定时获取更新数据
进行base64编码后保存至本地
上传只gitee同步远程仓库
"""
import base64
import os
import time
import requests
from main import Spider

def upload_file():
    url = "https://api.buliang0.cf/easyclash"
    # headers=Spider().headers
    with requests.get(url) as resp:
        prox_str = base64.b64decode(resp.text).decode(encoding="utf-8")

    with open("base64.txt",mode="w",encoding="utf-8") as f:
        f.write(prox_str)

    print("upload file over!")


def post_base():
    sys_str = [
        "cd D:\WPS Office\Study",
        "git add .",
        "git commit -m 'commit'",
        "git push"
    ]
    for str in sys_str:
        os.system(str)
        time.sleep(1)
    print("commit -- {}".format(time.strftime("%m/%d %X")))


def Waiting():
    sleep = 10
    print("Sleeping...")
    while True:
        time.sleep(60)
        sleep -= 1
        if sleep == 0:
            break
    upload_file()
    post_base()


def main():
    while True:
        Waiting()


if __name__ == '__main__':
    main()
    # upload_file()
    # post_base()
